    #!/bin/perl
package data;
    use strict;
    use DBI;
    use utf8;

	#这一句，可以避免出现由于变量只使用一次出现的 use only once 警告 
	no warnings('once');  
	#包含配置文件
	require '../conf/config.pl';
    
    our %db_conf = %conf::db_conf ; 
    my $db_host = $db_conf{'db_host'};
    my $db_user = $db_conf{'db_user'};
    my $db_pwd = $db_conf{'db_pwd'};

    # Connect to target DB
    my $dbh = DBI->connect("$db_host","$db_user","$db_pwd", {'RaiseError' => 1,'mysql_enable_utf8'=>1});

    my $contents="";

    # 修复IT助手的拥有者
    my $sql = <<"___SQLSTRING___";
select ta.tn as no from ticket ta left join (queue q,users u) on (q.id=ta.queue_id and u.id=ta.user_id) where u.first_name in ('报障中心') and q.name='IT助手'
___SQLSTRING___

    
    my $sqr = $dbh->prepare("$sql");

    $sqr->execute();

    while(my $ref = $sqr->fetchrow_hashref()) {

	$contents.="$ref->{'no'}/n";
	
	# execute UPDATE query
	my $rows = $dbh->do("update  ticket t,user_preferences up set t.user_id=up.user_id  where t.customer_user_id=up.preferences_value and t.user_id<>up.user_id and t.tn='$ref->{'no'}'");
	#print "$rows row(s) affected /n";


    }
    print $contents."Updated!";

    $dbh->disconnect();
   

